<?php
/**
 * changxm   会员管理
 * 2011-12 会员注册 等各种功能
 *
 */
class MemberAction extends Action
{
    protected $fields = array('name', 'password', 'e_mail');
    public function rtest(){
    	$m = M('Member');
    	$data['name']='ww';
    	$data['password']='ww';
    	$data['e_mail']='ww';
//    	if($m->data($data)->add()){
//    		$this->success('注册成功');
//    	}
    	
    }
	public function register(){    	
    	if($_POST){
    		//---
    		$param=$_POST;
			
    		$m = M('Member');
    		if($_POST['id']){    			
    			unset($param['id']);
    			$m->where('id='.$_POST['id'])->save($param);
    			$m->save();
    		}else{		
    			unset($param[id]);unset($param['password1']);
    			if(!$param['name'] || !$param['password'] || !$param['e_mail']){
					$this->error('所有各项都需要填写 ！');
				}
    			if($m->add($param)){
    				$this->success('注册成功');die();
    			}
    		}
    		//++++
    		
    		
//			$p = $_POST;
//			if(!$p['name'] || !$p['password'] || !$p['e_mail']){
//				$this->error('所有各项都需要填写 ！');
//			}
//			if ($p ['password'] != $p ['password1']) {
//				$this->error ( '两次输入密码不一样' );
//			}
//			foreach ( $p as $k => $v ) {
//				if(!in_array($k, $this->fields)){
//					unset($p[$k]);
//				}
//			}
//			$m = M('Member');
//			$m->create();$m->add();

			
//			var_dump($p);die();
//			if($p['name'] && $p['password'] && $p['email']){
//				if($m->add($p)){
//					$this->success('注册成功');
//				}
//			}
    	}
    	$this->assign('title','注册');
    	$this->display();
    }
    
    public function login(){
    	if($_POST){
    		$name=$_POST['name'];
    		$pwd = $_POST['password'];
    		$m = M('Member');
    		$m->where("name = '". $name . "' and password='".$pwd."'")->find();
    		if($m->name){
    			$_SESSION['name']=$name;
    			//$this->display("index","index");die();
    			
    			$this->redirect("Index/index");
    		}else{
    			echo 'nolll';
    		}
//    		$memberModel=new MemberModel();
//    		
//    		//var_dump($memberModel);die();
//    		if($memberModel->login($name)){
//    			$_SESSION['member']=$name;
//    			$this->display("index","index");
//    		}    
    	}
    	$this->display();
    }
    
    public function logout(){
    	$_SESSION['name']='';
    	$this->success('成功退出');
//    	echo $_SERVER['HTTP_REFERER'];
//    	
//    	die();
//    	$this->redirect($_SERVER['HTTP_REFERER']);
//    	
    }


}
?>